{% extends "cmdb/mequipment/index.html" %}

{% block right_content %}
<div id="right_menu">

    <div>
        <div class="form-group">
            <button id="add" class="btn btn-info hint hint-bottom" style="float:left;margin-right: 10px;" data-hint="添加一个服务器信息" ><span class="glyphicon glyphicon-plus"></span></button>
        </div>

        <form class="form-inline" style="float: right">
            <div class="form-group">
                <label for="equipmentType">类型: </label>
                <select type="text" id="equipmentType" class="form-control">
                    <option value="0">全部</option>
                    {% for idx,single_type in equipment_type_list.items %}
                    <option value="{{ idx }}" {% ifequal equipment_type idx %} selected {% endifequal %}>{{ single_type }}</option>
                    {% endfor %}
                </select>
            </div>
            <div class="form-group">
                <label for="serverRoomId">机房: </label>
                <select type="text" id="serverRoomId" class="form-control">
                    <option value="0">全部</option>
                    {% for single_room in server_room_list %}
                    <option value="{{ single_room.id }}" {% ifequal server_room_id single_room.id %} selected {% endifequal %}>{{ single_room.server_room }}</option>
                    {% endfor %}
                </select>
            </div>
            <div class="form-group">
                <label class="sr-only" for="sysInnerIp">Search</label>
                <input type="search" class="form-control" id="sysInnerIp" placeholder="内网ip/序列号" value="{{ search }}" style="width:100%">
            </div>
            <button type="button" class="btn btn-primary" id="searchEquipment"><span class="glyphicon glyphicon-search"></span></button>
        </form>
    </div>
    <table id="example" style="table-layout:fixed;" class="table table-bordered table-hover">
        <thead >
        <td class="col" style="width:8%">编号</td>
        <td class="col" style="width:6%">类型</td>
        <td class="col" style="width:8%">序列号</td>
        <td class="col" style="width:21%">主机名</td>
        <td class="col" style="width:10%">内网IP</td>
        <td class="col" style="width:12%">设备型号</td>
        <td class="col" style="width:8%">机房</td>
        <td class="col" style="width:10%">设备负责人</td>
        <td class="col" style="width:15%">操作</td>
        </thead>
        {% if equipment_list %}
        {% for equipment in equipment_list %}
        <tr>
            <td class="col">{{ equipment.equipment_no }}</td>
            <td class="col">{{ equipment.equipment_type_value }}</td>
            <td class="col">{{ equipment.serial_num }}</td>
            <td class="col">{{ equipment.hostname }}</td>
            <td class="col">{{ equipment.sys_ip_inner }}</td>
            <td class="col">{{ equipment.equipment_model }}</td>
            <td class="col">{{ equipment.server_room }}</td>
            <td class="col">{{ equipment.responser }}</td>
            <td class="col">
                 <div>

                    <a  class="edit_item mouse_pointer hint hint-top" data-id="{{ equipment.id }}" data-eno="{{ equipment.equipment_no }}" data-target="#editItem" data-hint="点击编辑服务器信息"><span class="glyphicon glyphicon-edit"></span></a>&nbsp;

                    <a data-eno="{{ equipment.equipment_no }}" class="mouse_pointer hint hint-top" data-toggle="modal" data-target="#lookItem" data-hint="点击查看服务器详情"><span class="glyphicon glyphicon-eye-open"></span></a>&nbsp;

                    <a data-eno="{{ equipment.equipment_no }}" class="delete_item mouse_pointer hint hint-top" data-hint="点击删除次条服务器信息"><span class="glyphicon glyphicon-trash"></span></a>

                 </div>
             </td>
        </tr>
        {% endfor %}
        {% endif %}
    </table>

    <div class="bottom_menu">
        <span>跳转到
         <select class="pagei">
             {% for temppage in page_list %}
             <option value="{{ temppage }}" {% ifequal temppage page %}selected {% endifequal %}>{{ temppage }}</option>
             {% endfor %}
         </select>页
        </span>
        <span style="padding-left: 28%;">每页{{ page_num }}条，第{{ page }}页，共{{ count }}条，共{{ page_total }}页</span>
        <span style="float:right;padding-right:50px">
            <a class="word hint hint-top" href="{% url 'equipment:home' %}?page=1&equipment_type={{ equipment_type }}&server_room_id={{ server_room_id }}&search={{ search }}" data-hint="首页"><span class="glyphicon glyphicon-fast-backward"></span></a>
            {% ifnotequal page 1 %}&nbsp;
            <a href="{% url 'equipment:home' %}?page={{ page|add:-1 }}&equipment_type={{ equipment_type }}&server_room_id={{ server_room_id }}&search={{ search }}" class="hint hint-top" data-hint="点击跳转到上一页"><span class="glyphicon glyphicon-step-backward"></span></a>
            {% endifnotequal %}
            {% ifnotequal page page_total %}&nbsp;
            <a href="{% url  'equipment:home' %}?page={{ page|add:1 }}&equipment_type={{ equipment_type }}&server_room_id={{ server_room_id }}&search={{ search }}" class="hint hint-top" data-hint="点击跳转到下一页"><span class="glyphicon glyphicon-step-forward"></span></a>
            {% endifnotequal %}&nbsp;
            <a class="word hint hint-top" href="{% url 'equipment:home' %}?page={{ page_total }}&equipment_type={{ equipment_type }}&server_room_id={{ server_room_id }}&search={{ search }}" data-hint="尾页"><span class="glyphicon glyphicon-fast-forward"></span></a>
        </span>
    </div>
</div>

<!-- 模态框（Modal）编辑用户资料 -->
<div class="modal fade" id="lookItem" tabindex="-1" role="dialog" aria-labelledby="lookItemLabel">
    <div class="modal-dialog">
        <div class="modal-content" style="width:800px">
            <div class="modal-header">
                <button type="button" class="close"
                        data-dismiss="modal">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    详情
                </h4>
            </div>
            <div class="modal-body item_details">

                <h4><strong>设备信息</strong></h4>
                <table class="table table-bordered table-hover">

                    <thead>
                        <td class="col1">设备类型</td>
                        <td class="col2">主机名</td>
                        <td class="col3">内网ip</td>
                        <td class="col4">外网ip</td>
                        <td class="col5">序列号</td>
                        <td class="col6">CPU</td>
                    </thead>
                    <tr class="detail_table_td_height">
                        <td class="col1" id="eType"></td>
                        <td class="col2" id="hostname"></td>
                        <td class="col3" id="sys_ip_inner"></td>
                        <td class="col4" id="sys_ip_outer"></td>
                        <td class="col5" id="serial_num"></td>
                        <td class="col6" id="cpu"></td>
                    </tr>
                </table>

                <table class="table table-bordered table-hover">
                    <thead>
                        <td class="col1">内存</td>
                        <td class="col2">硬盘</td>
                        <td class="col3">使用环境</td>
                        <td class="col4">机房</td>
                        <td class="col5">房间号</td>
                        <td class="col6">机柜</td>
                    </thead>
                    <tr class="detail_table_td_height">
                        <td class="col1" id="memory"></td>
                        <td class="col2" id="harddisk"></td>
                        <td class="col3" id="environment"></td>
                        <td class="col4" id="server_room"></td>
                        <td class="col5" id="room_no"></td>
                        <td class="col6" id="cabinet"></td>
                    </tr>

                </table>

                <table class="table table-bordered table-hover">
                    <thead>
                        <td class="col1">占用U数</td>
                        <td class="col2">机柜起位</td>
                        <td class="col3">机柜止位</td>
                        <td class="col4">所在机位</td>
                        <td class="col5">起始日期</td>
                        <td class="col6">维保到期</td>
                    </thead>
                    <tr class="detail_table_td_height">
                        <td class="col1" id="occupy_u"></td>
                        <td class="col2" id="start_cabinet"></td>
                        <td class="col3" id="end_cabinet"></td>
                        <td class="col4" id="machine_pos"></td>
                        <td class="col5" id="start_time"></td>
                        <td class="col6" id="maint_end_time"></td>
                    </tr>
                </table>

                <table class="table table-bordered table-hover">
                    <thead>
                        <td class="col1">制造商</td>
                        <td class="col2">供应商</td>
                        <td class="col3">资产编号</td>
                        <td class="col4">管理地址</td>
                        <td class="col5">cpu型号</td>
                        <td class="col6">设备负责人</td>
                    </thead>
                    <tr class="detail_table_td_height">
                        <td class="col1" id="manufacturer"></td>
                        <td class="col2" id="provider"></td>
                        <td class="col3" id="asset_number"></td>
                        <td class="col4" id="idrac"></td>
                        <td class="col4" id="cpu_model"></td>
                        <td class="col6" id="responser"></td>
                    </tr>
                </table>

                <table class="table table-bordered table-hover">
                    <thead>
                        <td colspan="6">备注</td>
                    </thead>
                    <tr class="detail_table_td_height">
                        <td colspan="6" id="comment1" ></td>
                    </tr>
                </table>

                <table class="table table-bordered table-hover">
                    <thead>
                        <td class="col1">网卡名</td>
                        <td colspan="5">MAC地址</td>
                    </thead>
                    <tbody id="physicalAddr" class="detail_table_td_height">

                    </tbody>

                </table>

                <h4><b>系统信息</b></h4>
                <table class="table table-bordered table-hover">
                    <thead>
                        <td class="col1">系统版本</td>
                        <td class="col2">内核版本</td>
                        <td class="col3">系统父ip</td>
                        <td class="col4">使用状态</td>
                    </thead>
                    <tr class="detail_table_td_height">
                        <td class="col1" id="system_ver"></td>
                        <td class="col2" id="core_ver"></td>
                        <td class="col3" id="sys_parent_ip"></td>
                        <td class="col4" id="use_status"></td>
                    </tr>
                </table>

                <table class="table table-bordered table-hover">
                    <thead>
                        <td colspan="4">备注</td>
                    </thead>
                    <tr class="detail_table_td_height">
                        <td colspan="4" id="comment2"></td>
                    </tr>
                </table>

                <table class="table table-bordered table-hover">
                    <thead>
                       <td colspan="4">所属系统</td>
                    </thead>

                    <tbody id="belong_sys_info" class="detail_table_td_height">

                    </tbody>
                </table>

                <h4><b>部署模块</b></h4>
                <table class="table table-bordered table-hover" id="deploy_module_list">
                    <thead>
                       <td class="col1">模块</td>
                       <td class="col2">server port</td>
                        <td class="col3">状态</td>
                    </thead>
                    <tbody class="detail_table_td_height">

                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(".pagei").change(function(){
        var index=$(this).children('option:selected').val();
        var ip = $("#sysInnerIp").val();
        if(ip!=''){
            window.location.href="{% url 'equipment:home' %}?page=" + index + "&equipment_type={{ equipment_type }}&server_room_id={{ server_room_id }}&search="+ip;
        }else{
            window.location.href="{% url 'equipment:home' %}?page=" +index + "&equipment_type={{ equipment_type }}&server_room_id={{ server_room_id }}";
        }
    });
    $("#add").click(function(){
        window.location.href="{% url 'equipment:equipmentadd' %}";
    });

    $("#lookItem").on('show.bs.modal',function(event){
        var button = $(event.relatedTarget);
        var eNo = button.data("eno");

        var urls = "{% url 'equipment:eqgetaction' %}";
        postdata = {eNo:eNo};
        var jsonstr = $.ajax({
			url : urls,
			type : "POST",
			data : postdata,
			async : false,
			cache : false
		});
		var jsonobj = eval('(' + jsonstr.responseText + ')');
		if(jsonobj.status==0){
		    alert(jsonobj.message);
		}else{
            $(this).find('#eNo').html(eNo);
            $(this).find('#eType').html(jsonobj.data.equipment_info.equipment_type_name);
            $(this).find('#hostname').html(jsonobj.data.equipment_info.hostname);
            $(this).find('#sys_ip_inner').html(jsonobj.data.equipment_info.sys_ip_inner);
            $(this).find('#mac').html(jsonobj.data.equipment_info.mac);
            $(this).find('#sys_ip_outer').html(jsonobj.data.equipment_info.sys_ip_outer);
            $(this).find('#serial_num').html(jsonobj.data.equipment_info.serial_num);
            $(this).find('#asset_number').html(jsonobj.data.equipment_info.asset_number);
            $(this).find('#cpu').html(jsonobj.data.equipment_info.cpu);
            $(this).find('#memory').html(jsonobj.data.equipment_info.memory);
            $(this).find('#harddisk').html(jsonobj.data.equipment_info.harddisk);
            $(this).find('#environment').html(jsonobj.data.equipment_info.environment_desc);
            $(this).find('#server_room').html(jsonobj.data.server_room);
            $(this).find('#room_no').html(jsonobj.data.room_no);
            $(this).find('#cabinet').html(jsonobj.data.equipment_info.cabinet);
            $(this).find('#occupy_u').html(jsonobj.data.equipment_info.occupy_u);
            $(this).find('#start_cabinet').html(jsonobj.data.equipment_info.start_cabinet);
            $(this).find('#end_cabinet').html(jsonobj.data.equipment_info.end_cabinet);
            $(this).find('#machine_pos').html(jsonobj.data.equipment_info.machine_pos);
            $(this).find('#start_time').html(jsonobj.data.equipment_info.start_time);
            $(this).find('#maint_end_time').html(jsonobj.data.equipment_info.maint_end_time);
            $(this).find('#manufacturer').html(jsonobj.data.manufacturer);
            $(this).find('#provider').html(jsonobj.data.provider);
            $(this).find('#idrac').html(jsonobj.data.equipment_info.idrac);
            $(this).find('#comment1').html(jsonobj.data.equipment_info.comment);
            $(this).find('#responser').html(jsonobj.data.equipment_info.responser);
            $(this).find('#cpu_model').html(jsonobj.data.equipment_info.cpu_model);

            $(this).find('tbody#physicalAddr').html('');
            if(typeof(jsonobj.data.network_card_info) != "undefined"){
                for(var idx in jsonobj.data.network_card_info){
                    var tmpCard = jsonobj.data.network_card_info[idx];
                    $(this).find('tbody#physicalAddr').append('<tr><td class="col1">' + tmpCard.card_name + '</td>'
                                                              + '<td colspan="5">' + tmpCard.mac + '</td>'
                                                              +'</tr>');
                }
            }

            $(this).find('#system_ver').html(jsonobj.data.system_info.system_ver);
            $(this).find('#core_ver').html(jsonobj.data.system_info.core_ver);
            $(this).find('#sys_parent_ip').html(jsonobj.data.system_info.sys_parent_ip);
            $(this).find('#use_status').html(jsonobj.data.system_info.use_status_desc);
            $(this).find('#comment2').html(jsonobj.data.system_info.comment);
            $(this).find('tbody#belong_sys_info').html('');
            if(typeof(jsonobj.data.belong_system_list) != "undefined"){
                for(var idx in jsonobj.data.belong_system_list){
                   var tempSys = jsonobj.data.belong_system_list[idx];
                   $(this).find('tbody#belong_sys_info').append('<tr><td colspan=4">' + tempSys.belong_sys_name + '</td></tr>');
                }
            }else{
                $(this).find('tbody#belong_sys_info').html('<tr><td colspan="4">无</td></tr>');
            }
            $('#deploy_module_list tbody').html("");
            if(typeof(jsonobj.data.business_server_mapping_list) != "undefined"){
                for(var idx in jsonobj.data.business_server_mapping_list){
                    var tempBusiness = jsonobj.data.business_server_mapping_list[idx];
                    $('#deploy_module_list tbody').append('<tr><td>' + tempBusiness.module_name +  '</td>'  + '<td>' + tempBusiness.server_port +  '</td>'  + '<td>' + tempBusiness.use_status_desc + '</td></tr>');
                }
            }else{
                $('#deploy_module_list tbody').append('<tr><td colspan="2">无</td></tr>');
            }

        }

    });

    $(".edit_item").click(function(){
        var eNo = $(this).data("eno");
        window.location.href="{% url 'equipment:equipmentedit' %}?page=" + {{ page }} + "&equipment_no="+eNo;
    });

    $(".delete_item").click(function(){
        if(confirm("确定要删除吗？删除操作不可恢复！")) {
           var eNo = $(this).data("eno");
           var urls = "{% url 'equipment:eqdeleteaction' %}";
           var postdata = {eNo:eNo}
           var jsonstr = $.ajax({
			url : urls,
			type : "POST",
			data : postdata,
			async : false,
			cache : false
		  });

	     var jsonobj = eval('(' + jsonstr.responseText + ')');
		  if(jsonobj.status==0){
		      alert(jsonobj.message);
		  }else{
              window.location.reload();
          }
        }
    });

    $("#searchEquipment").click(function(){
        var ip = $("#sysInnerIp").val();
        var equipmentType = $("#equipmentType").val();
        var serverRoomId = $("#serverRoomId").val();
        window.location.href="{% url 'equipment:home' %}?equipment_type=" + equipmentType + "&server_room_id=" + serverRoomId + "&search="+ip;
    });

</script>
{% endblock %}

